package com.mypage.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;

import com.cloudcc.mobile.R;
import com.cloudcc.mobile.entity.beau.BeauInfoEntity;
import com.cloudcc.mobile.entity.beau.BeauRecordTypeEntity;

import java.util.HashMap;
import java.util.List;

/**
 * Created by liuyongjie on 2017/5/17.
 */

public class NchageRecorderAdapter extends BaseAdapter {
    public List<BeauRecordTypeEntity> mxList;
    public List<BeauInfoEntity.ObjChange.TypeChange> mList;
    public Context context;
    // 用来控制CheckBox的选中状况
    private static HashMap<Integer,Boolean> isSelected;
  private String mType;
    public NchageRecorderAdapter(Context context, List<BeauInfoEntity.ObjChange.TypeChange> mList,String mType) {
        this.mList = mList;
        this.context = context;
        this.mType = mType;
        isSelected = new HashMap<Integer, Boolean>();
        initDate();
    }
    public NchageRecorderAdapter(Context context, List<BeauInfoEntity.ObjChange.TypeChange> mList) {
        this.mList = mList;
        this.context = context;
        isSelected = new HashMap<Integer, Boolean>();
        initDate();
    }
//    public NchageRecorderAdapter(Context context, List<BeauRecordTypeEntity> mxList) {
//        this.mxList = mxList;
//        this.context = context;
//        isSelected = new HashMap<Integer, Boolean>();
//        initDate();
//    }
    // 初始化isSelected的数据
    private void initDate(){
        for(int i=0; i<mList.size();i++) {
            getIsSelected().put(i,false);
        }
    }
    @Override
    public int getCount() {
        return mList.size()==0?0:mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder h = null;
        if (convertView==null){
            h = new ViewHolder();
            convertView = View.inflate(context, R.layout.change_reocoder_type_item,null);
            h.checkBox = (CheckBox) convertView.findViewById(R.id.checkBox);
            convertView.setTag(h);
        }else{
            h = (ViewHolder) convertView.getTag();
        }
        h.checkBox.setText("  "+String.valueOf(mList.get(position).name));
//        if (mType.equals(mList.get(position).Id)){
//            h.checkBox.setChecked(true);
//        }
        h.checkBox.setChecked(getIsSelected().get(position));
        return convertView;
    }
    public class ViewHolder{
        public CheckBox checkBox;
    }
    public static HashMap<Integer,Boolean> getIsSelected() {
        return isSelected;
    }
    public static void setIsSelected(HashMap<Integer,Boolean> isSelected) {
        NchageRecorderAdapter.isSelected = isSelected;
    }
}
